<template>
    <view class="unpaidList">
        <view class="item">
            <view class="bookInfo">
                <u--image height="6rem" width="6rem" :src="unpaidItem.bookLink"></u--image>
                <view class="midInfo">
                    <view class="title">{{ unpaidItem.title }}</view>
                    <view class="author">作者：{{ unpaidItem.author }}</view>
                </view>
                <view class="bookState" v-if="unpaidItem.isCancel == false">
                    待支付
                </view>
                <view class="bookState" v-else>
                    已关闭
                </view>
            </view>
            <view class="closeTime" v-if="unpaidItem.isCancel == false">
                <u-count-down class="countDown" :time="closeTime(unpaidItem)" format="mm:ss"></u-count-down>
                <span>后自动关闭订单，建议尽快付款</span>
            </view>
            <view class="price" v-if="unpaidItem.isCancel == false">需付款￥{{ unpaidItem.price }}</view>
            <view class="operate" v-if="unpaidItem.isCancel == false">
                <u-button class="btn closeOrder" type="primary" size="small" @click="cancelOrder">取消订单
                </u-button>
                <view class="right">
                    <u-button class="btn" type="primary" size="small" @click="updateAddress">修改地址
                    </u-button>
                    <u-button class="btn pay" type="primary" size="small" @click="pay">付款</u-button>
                </view>
            </view>
            <view class="operate" v-else>
                <u-button class="btn closeOrder " style="margin: 0" type="primary" size="small" @click="cancelOrder">
                    删除订单
                </u-button>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    name: 'unpaidOrderList',
    props: {
        unpaidItem: {
            type: Object,
            default: () => { }
        }
    },
    computed: {
        closeTime() {
            return function (item) {
                // 15分钟后自动关闭订单，建议尽快付款
                var now = new Date().getTime();
                var orderTime = new Date(item.orderTime).getTime();
                var closeTime = new Date(orderTime + 15 * 60 * 1000).getTime();
                var diff = (closeTime - now)
                if (diff < 0) {
                    // 向后端发送请求，关闭订单
                    { }
                    return 0;
                }
                return diff;
            }
        },
    },
    methods: {
        cancelOrder() {
            console.log('取消订单')
        },
        updateAddress() {
            console.log('修改地址')
        },
        pay() {
             this.$Router.push({
                   name:'pay'
               })
            console.log('付款')
        },
    }

}
</script>

<style lang="scss">
.unpaidList {
    width: 100%;
    margin-bottom: 1rem;

    .item {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
        background: white;
        border-radius: 1rem;
        padding: 0.5rem;
        // margin: 1rem 0;

        .bookInfo {
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            align-items: center;
            width: 100%;

            .midInfo {
                margin-left: 1rem;

                .title {
                    font-size: 1.2rem;
                    font-weight: bold;
                    color: #333;
                }

                .author {
                    font-size: 0.8rem;
                    color: #999;
                }
            }

            .bookState {
                position: absolute;
                right: 1rem;
            }
        }

        .closeTime {
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            background: $uni-color-theme-1;
            color: $uni-color-theme-9;
            padding: 0.5rem 1.5rem;
            border-radius: 0.5rem;
            margin: 0.5rem 0;
            margin-left: 1rem;

            .countDown {
                padding-right: 0.5rem;
            }

        }

        .logisticsStatus {
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            align-items: center;
            background: $uni-color-theme-1;
            color: rgb(53, 53, 53);
            padding: 0.5rem 1.5rem;
            border-radius: 0.5rem;
            margin: 0.5rem 0;
            margin-left: 1rem;
            font-weight: bold;
            overflow: hidden;
            width: 18rem;
            white-space: nowrap;

            i {
                margin-right: 0.5rem;
                font-size: 1.2rem;

            }

            .status {
                display: inline-block;
                margin-left: 0.5rem;
                line-height: 1rem;
                font-size: 0.6rem;
            }
        }

        .price {
            width: 90%;
            text-align: end;
        }

        .operate {
            display: flex;
            flex-direction: row;
            justify-content: flex-end;
            // align-items: center;
            width: 100%;
            margin-top: 0.5rem;

            .btn {
                width: 6rem;
                height: 2rem;
                border: none;
                background: transparent;
                color: #333;
                font-size: 0.8rem;
                text-align: center;
                line-height: 1.5rem;
                font-size: 1rem;
                margin: 0 0.5rem;
            }

            .closeOrder {
                margin-right: 3rem;
                font-size: 0.8rem;
                color: $uni-text-color-grey;
            }

            .right {
                display: flex;
                flex-direction: row;

                .btn {
                    border-radius: 1rem;
                    border: 1px solid $uni-text-color-grey;
                    color: $uni-text-color-grey;
                }

                .pay {
                    border-radius: 1rem;
                    border: 1px solid $uni-color-theme-6;
                    color: $uni-color-theme-6;
                }

            }
        }
    }
}
</style>